package com.demo.swagger.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@Configuration
// 开启Swagger2
@EnableSwagger2
public class SwaggerConfig {
	@Bean
	public Docket api() {
		// 扫描路径
		// RequestHandlerSelectors.basePackage("com.demo")
		// RequestHandlerSelectors.any() 所有
		// 过滤的接口
		// PathSelectors.any() 所有，不过滤
		// PathSelectors.regex("/swagger/*") 过滤以下路径 如：/swagger/login
		return new Docket(DocumentationType.SWAGGER_2).select()
				.apis(RequestHandlerSelectors.basePackage("com.demo.swagger.controller")).paths(PathSelectors.any())
				.build().apiInfo(apiInfo());
	}

	private ApiInfo apiInfo() {
		ApiInfo apiInfo = new ApiInfo("Spring Boot REST API Demo by Pakho", "Spring Boot REST API for Simple Demo",
				"1.0", "ServiceUrl", new Contact("Pakho", "https://github.com/pakho", "359396547@qq.com"),
				"Apache License Version 2.0", "https://www.apache.org/licenses/LICENSE-2.0");
		return apiInfo;
	}
}
